﻿package net.wangit.view.chart.impl;

import java.awt.Color;

import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.labels.StandardCategoryToolTipGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.Marker;
import org.jfree.chart.plot.ValueMarker;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.chart.renderer.category.WaterfallBarRenderer;
import org.jfree.chart.urls.StandardCategoryURLGenerator;
import org.jfree.data.category.CategoryDataset;
import org.jfree.ui.Layer;

public class WaterfallChart extends CategoryChart {

	public WaterfallChart() {
	}

	protected CategoryPlot getCategoryPlot() {
		CategoryDataset dataset = (CategoryDataset) getDataset();
		CategoryAxis categoryAxis = getCategoryAxis();
		categoryAxis.setCategoryMargin(0.0D);
		org.jfree.chart.axis.ValueAxis valueAxis = getNumberAxis();
		CategoryItemRenderer renderer = getRenderer();
		CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis,
				renderer);
		plot.clearRangeMarkers();
		Marker baseline = new ValueMarker(0.0D);
		baseline.setPaint(Color.black);
		plot.addRangeMarker(baseline, Layer.FOREGROUND);
		plot.setOrientation(orientation);
		return plot;
	}

	private CategoryItemRenderer getRenderer() {
		WaterfallBarRenderer renderer = new WaterfallBarRenderer();
		if (tooltips) {
			StandardCategoryToolTipGenerator generator = new StandardCategoryToolTipGenerator();
			renderer.setBaseToolTipGenerator(generator);
		}
		if (urls)
			renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator(
					url));
		configCategoryRenderer(renderer);
		return renderer;
	}
}
